#!/usr/local/bin/php
<?php
/**
 * Created by PhpStorm.
 * User: chenxuyi
 * Date: 2017/7/4
 * Time: 下午2:40
 */

PHP_SAPI != 'cli' && die("Please run by command\n");

define('ROOT_PATH', __DIR__);
define('SYS_PATH', ROOT_PATH.'/System');
define('LIB_PATH', ROOT_PATH.'/Libraries');
define('HELP_PATH', ROOT_PATH.'/Helpers');
define('TEMPLATE_PATH', ROOT_PATH.'/Template');

require_once SYS_PATH.'/App.php';         //加载应用核心文件
require_once HELP_PATH.'/TplHelper.php';  //加载辅助函数
require_once HELP_PATH.'/FunctionsHelper.php';  //加载辅助函数

$params       = array_slice($argv, 2, count($argv) - 2);
$commandGroup = isset($argv[1]) ? $argv[1] : 'help';
$commands     = explode(':', $commandGroup);

try {
    $class    = '\Terminal\\'.ucfirst($commands[0]);
    $terminal = new $class($commands, $params);
    $terminal->handle();
} catch (Exception $exception) {
    echo $exception->getMessage();
    echo "\n\nusage:\n";
    echo \terminal\Help::$help[$exception->getCode()];
    echo "\n";
    die;
}
